﻿using Microsoft.AspNetCore.Mvc;
using System;
using Think9.Controllers.Basic;
using Think9.Models;
using Think9.Services.Basic;

namespace Think9.Controllers.Web.Donation.Controllers
{
    public class DonationController : BaseController
    {
        //public IDonationService DonationService2 { get; set; }

        private DonationService DonationService = new DonationService();

        // GET: Donation/Donation
        public override ActionResult Index(int? id)
        {
            base.Index(id);
            return View();
        }

        [HttpGet]
        public JsonResult List(DonationEntity model, PageInfoEntity pageInfo)
        {
            var result = DonationService.GetListByFilter(model, pageInfo);
            return Json(result);
        }

        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(DonationEntity model)
        {
            model.CreateTime = DateTime.Now;
            var result = DonationService.Insert(model) ? SuccessTip("添加成功") : ErrorTip("添加失败");
            return Json(result);
        }

        public ActionResult Edit(int id)
        {
            var model = DonationService.GetById(id);
            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(DonationEntity model)
        {
            var result = DonationService.UpdateById(model) ? SuccessTip("编辑成功") : ErrorTip("编辑失败");
            return Json(result);
        }

        [HttpGet]
        public JsonResult Delete(int id)
        {
            var result = DonationService.DeleteById(id) ? SuccessTip("删除成功") : ErrorTip("删除失败");
            return Json(result);
        }
    }
}